#ifndef TASK_POLLER_H
#define TASK_POLLER_H

#include "copy/noncopyable.h"
#include "EventLoop.h"
#include "Timestamp.h"

#include <vector>
#include <map>

struct pollfd;
class Channel;


class Poller : muduo::noncopyable{
public:
    typedef std::vector<Channel *> ChannelList;

    Poller(EventLoop * loop);
    ~Poller();

    Timestamp poll(int timeoutMs, ChannelList * activeChannels);

    void updateChannel(Channel * channel);

    void assertInLoopThread(){
        ownerLoop_->assertInLoopThread();
    }

private:
    void fillActiveChannels(int numEvents, ChannelList * activeChannels)const;

    typedef std::vector<struct pollfd> PollFdList;
    typedef std::map<int, Channel *> ChannelMap;

    EventLoop * ownerLoop_;
    PollFdList pollfds_;
    ChannelMap channels_;
};

#endif //TASK_POLLER_H
